package admin

import (
	"fmt"
	"net/http"
	"strconv"

	"github.com/convee/goblog/internal/pkg/mysql"
	"github.com/convee/goblog/internal/pkg/view"
)

func VisitLogPageList(w http.ResponseWriter, r *http.Request) {
	perPage, _ := strconv.Atoi(r.URL.Query().Get("per_page"))
	page, _ := strconv.Atoi(r.URL.Query().Get("page"))
	if perPage <= 0 {
		perPage = 20
	}
	if page <= 1 {
		page = 1
	}
	pages, err := mysql.VisitLogPageList(mysql.PageParams{
		PerPage: perPage,
		Page:    page,
	})
	if err != nil {
		fmt.Println("get VisitLogPageList err:", err)
		return
	}
	data := make(map[string]interface{})
	data["visitlogs"] = pages
	view.AdminRender(data, w, "visitlog/list")
}
